home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 6 / cl0588.zip / GETOP.C < prev    next >
Text File  |  1988-01-21  |  777b  |  39 lines

  1. /* .subt |Get operation type for desktop calculator */
  2.  
  3. getop(s,lim)
  4. char s[];
  5. int  lim;
  6. {
  7.   int  i, c;
  8.  
  9.   while ((c = getch()) == ' ' || c == '\t' || c == '\n')
  10.         ;
  11.   if (c != '.' && (c < '0' || c > '9'))
  12.         return(c);
  13.   s[0] = c;
  14.   for (i = 1; (c = getchar()) >= '0' && c <= '9'; i++)
  15.       if (i < lim)
  16.          s[i] = c;
  17.   if (c == '.') {
  18.      if (i < lim)
  19.         s[i] = c;
  20.      for (i++; (c = getchar()) >= '0' && c <= '9'; i++)
  21.          if (i<lim)
  22.             s[i] = c;
  23.   }
  24.   if (i < lim) {
  25.      ungetch(c);
  26.      s[i] = '\0';
  27.      return(NUMBER);
  28.   }
  29.   else {
  30.     while (c != '\n' && c != EOF)
  31.           c = getchar();
  32.           s[lim-1] = '\0';
  33.           return(TOOBIG);
  34.   }
  35. }
  36.  
  37. /* .subt < end of file, file getop.c */
  38.  
  39.